'''[补ac]赛后打了很多补丁才过'''

def method(a):
    # 预处理，右端左同化，左端又同化，到不同或端点为止
    t = a[0]
    if t != 0:
        for i in range(len(a) - 1):
            if a[i] == 0:
                a[i] = t
            elif a[i] != t:
                break
    t = a[-1]
    if t != 0:
        for i in range(len(a) - 1, 0, -1):
            if a[i] == 0:
                a[i] = t
            elif a[i] != t:
                break

    # 0 取出所有非零数字，排序
    d = {}
    for i, x in enumerate(a):
        # if x not in d and not x == 0:
        #     d[x] = i
        if not x == 0:
            d[x] = i
    nums = list(d.keys())
    nums2 = nums.copy()

    # print(nums)
    # 1 判断有解（不全面）
    no_jie = len(nums) > 1 and nums[-1] - nums[0] > 1
    if no_jie:
        return -1

    nums.sort()

    # 2 要补的数字，和补数中分线
    l, r = 0, 0
    mid = 0
    if len(nums) == 0:
        l, r = 1, 2
        mid = 0
    elif len(nums) == 1:
        l, r = nums[0], nums[0] + 1
        if nums[0] >= 10**9:
            l, r = nums[0] - 1, nums[0]
        mid = d[l]
        # 右端点
        if d[l] == len(a) - 1:
            l, r = nums[0] - 1, nums[0 ]
            mid = d[r]
            # 但是左边不能是0
            if l == 0:
                l = 2
    elif len(nums) == 2:
        l, r = nums2[0], nums2[1]
        mid = d[l]

    # 3 开始补
    # print('l r mid', l, r, mid)
    for i in range(len(a)):
        if a[i] == 0:
            if i <= mid:
                a[i] = l
            elif i > mid:
                a[i] = r
    # print(a)

    # 4 再测有解
    s = 0
    for i in range(len(a) - 1):
        t = a[i+1] - a[i]
        t = t if t > 0 else -t 
        s += t 
    if s != 1:
        return -1
    return ' '.join([str(x) for x in a])

_ = int(input())
a = [int(x) for x in input().split(' ')]
ans = method(a)
print(ans)
